from commands import add, admin
import commands
     
@admin
def onehitkill(connection):
    if connection.protocol.onehit == True:
        connection.protocol.send_chat('One Hit Kill Disabled.')
        connection.protocol.onehit = False
    else:
        if connection.protocol.onehit is None:
            connection.protocol.onehit = set()
        connection.protocol.send_chat('One Hit Kill Enabled.')
        connection.protocol.onehit = True
add(onehitkill)

def apply_script(protocol, connection, config):
    
    class OneHitConnection(connection):
          def on_hit(self, hit_amount, hit_player):
              value = connection.on_hit(self, hit_amount, hit_player)
              if value is not None:
                  return value
              if self.protocol.onehit == True:
                  return 100
    class OneHitProtocol(protocol):
        onehit = None
    return OneHitProtocol, OneHitConnection